import render from './url-render.js';

const DEBUG = false;

export const API = {
  get(name, data, options = {}) {
    const settings = Object.assign({ debug: DEBUG, base: '' }, options);
    const url = this.urls[name];
    if (!url) throw new Error(name + ' not found!');
    if (settings.debug) {
      return `/static/json/${name}.json`;
    }
    const host = window.HOST || location.host;
    return render(`${location.protocol}//${host}${settings.base}${url}`, data);
  },
  dget(name, data) {
    return this.get(name, data, { debug: true });
  },
  extend(obj) {
    this.urls = Object.assign(this.urls, obj);
  },
  urls: {
    'test': '/customer/feign/show', //  test
  }
}
